package com.tangula.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import com.tangula.web.kashine.business.BusinessFailException;
import com.tangula.web.kashine.entity.BaseRespEntity;







public interface ReturnRespController {
	
	default <T> ResponseEntity<BaseRespEntity<T>> returnSuccess(T body){

		return new ResponseEntity<BaseRespEntity<T>>(new BaseRespEntity<T>(body),HttpStatus.OK);
	}
	
	
	default <T> ResponseEntity<BaseRespEntity<T>> returnBadRequest(String message){
		return new ResponseEntity<BaseRespEntity<T>>(new BaseRespEntity<T>(1, message!=null?message:"请求格式不正确"),HttpStatus.BAD_REQUEST);
	}
	
	default <T> ResponseEntity<BaseRespEntity<T>> returnServerError(String message){
		return new ResponseEntity<BaseRespEntity<T>>(new BaseRespEntity<T>(2, message!=null?message:"服务端出错，请联系管理员."),HttpStatus.INTERNAL_SERVER_ERROR);
	}
	
	default <T> ResponseEntity<BaseRespEntity<T>> returnBusinessFail(BusinessFailException ex, T body) {
		return new ResponseEntity<BaseRespEntity<T>>(new BaseRespEntity<T>(9999, ex.getLocalizedMessage(), body),HttpStatus.ACCEPTED);
	}

}
